
//KY11 二叉树遍历(牛客网)

import java.util.Scanner;
class TreeNode {
    public char val;
    public TreeNode left;
    public TreeNode right;
    public TreeNode (char val) {
        this.val = val;
    }
}
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Solution1 {
    //i为静态变量实时更新值
    static int i=0;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String s=in.nextLine();
            TreeNode root=createTree(s);
            inOrder(root);
        }
    }
    //通过先序遍历创建二叉树
    public static TreeNode createTree(String s){
        TreeNode root=null;
        if(s.charAt(i)!='#'){
            //先确定根再确定左右结点
            TreeNode tmp=new TreeNode(s.charAt(i));
            i++;
            root=tmp;
            root.left=createTree(s);
            //由于i是静态变量，所以确定右结点的时候才能遍历到字符串的那个下标
            root.right=createTree(s);
        }else{
            //为空就下一个
            i++;
        }
        return root;
    }
    //中序遍历
    public static void inOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }
}